package com.example.yiwei.crm.view.activity.jtCustomer;

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.BaseActivity;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.data.GetContact;
import com.example.yiwei.crm.data.GetCustomerData;
import com.example.yiwei.crm.data.GetCustumer;
import com.example.yiwei.crm.entity.CustomerMessageEntity;
import com.example.yiwei.crm.json.CoorCustomerJson;
import com.example.yiwei.crm.json.contactJson;
import com.example.yiwei.crm.json.customerJson;
import com.example.yiwei.crm.readcard.MainActivitycard;
import com.example.yiwei.crm.util.NetWorkUtils;
import com.example.yiwei.crm.util.SC;
import com.example.yiwei.crm.view.Class.listviewClass.AutoListView;
import com.example.yiwei.crm.view.Class.listviewClass.ListViewAdapter;
import com.example.yiwei.crm.view.activity.coordinationActivity.CoordinationGiftActivity;
import com.example.yiwei.crm.view.activity.coordinationActivity.CoordinationVisitActivitu;
import com.example.yiwei.crm.view.activity.coordinationActivity.CoordingCommunicateActivity;
import com.example.yiwei.crm.view.activity.coordinationActivity.CoordingCustomerSearchActivity;
import com.example.yiwei.crm.view.activity.coordinationActivity.OperationLogActivity;
import com.example.yiwei.crm.view.activity.coordinationActivity.SimpleintmentActivity;
import com.example.yiwei.crm.view.activity.customerActivity.CustomerAddActivity;
import com.example.yiwei.crm.view.activity.customerActivity.CustomerAppointmentAcitity;
import com.example.yiwei.crm.view.activity.customerActivity.CustomerDetailedMessageActivity;
import com.example.yiwei.crm.view.activity.menuActivity.HomeActivity;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
import com.oguzdev.circularfloatingactionmenu.library.SubActionButton;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;


public class SimpleJtCustomerActivity extends BaseActivity implements AutoListView.OnRefreshListener,AutoListView.OnLoadListener,View.OnClickListener {
    private AutoListView listView;
    ImageView fabIconStar;
    FloatingActionMenu leftCenterMenu;
    //    FloatingActionMenu leftCenterMenu1;
    FloatingActionButton leftCenterButton;
    private ListViewAdapter adapter;
    private List<CustomerMessageEntity> list;
    private List<CustomerMessageEntity> alist;
    private CustomerMessageEntity customer;
    ImageView img_search;
    private SharedPreferences sp;
    int page = 1;
    int a=1;
    String customer_tag = "";
    ImageView lcIcon1 ;
    ImageView lcIcon2 ;
    ImageView lcIcon3 ;
    ImageView lcIcon4 ;
    ImageView lcIcon5 ;
    private ImageView img_shouye,img_more1;
    private PopupWindow mPopWindow;
    private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            List<CustomerMessageEntity> result = (List<CustomerMessageEntity>) msg.obj;
            switch (msg.what) {
                case AutoListView.REFRESH:
                    listView.onRefreshComplete();
                    if (list!=null){
                        list.clear();
                    }
                    if (list!=null){
                        list.addAll(result);
                    }else {
                        list = result;
                    }
                    if (a==1){
                        adapter = new ListViewAdapter(SimpleJtCustomerActivity.this,list);
                        listView.setAdapter(adapter);
                        a++;
                    }

                    break;
                case AutoListView.LOAD:
                    listView.onLoadComplete();
                    if (result!=null){
                        list.addAll(result);
                    }

                    break;
            }
            if (result!=null) {
//                listView.setResultSize(result.size());
            }else{
//                listView.setResultSize(0);
            }
            adapter.notifyDataSetChanged();

        }


    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coor_customer);
        GetCustomerData.crateData();
        GetCustomerData.customers=null;
        list = new ArrayList<>();
        img_shouye= (ImageView) findViewById(R.id.simple_coording_img_shouye);
        img_more1= (ImageView) findViewById(R.id.simple_coording_img_more);
        listView= (AutoListView) findViewById(R.id.coor_custmer_alv);
        img_search= (ImageView) findViewById(R.id.customerSimpleMessage_btn_search);
        listView.setDivider(new ColorDrawable(Color.rgb(216, 216, 216)));
        listView.setDividerHeight(1);
        listView.setOnRefreshListener(this);
        listView.setOnLoadListener(this);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
        addXuanFu1();
        //悬浮按钮的监听
        leftCenterMenu.setStateChangeListener(new FloatingActionMenu.MenuStateChangeListener() {
            @Override
            public void onMenuOpened(FloatingActionMenu floatingActionMenu) {
                /*
                /构建两层按钮可使两个menu的点击按钮重合，当点击外层按钮用open方法使内层按钮展开，关闭同理
                 */
//                leftCenterMenu1.open(true);
                // 增加按钮中的+号图标顺时针旋转45度
//                // Rotate the icon of rightLowerButton 45 degrees clockwise
//                icon.setRotation(0);
//                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 45);
//                ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(icon, pvhR);
//                animation.start();
                //按钮的初始角度
                fabIconStar.setRotation(0);
                //按钮的旋转角度
                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 45);
                ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(fabIconStar, pvhR);
                animator.start();

            }

            @Override
            public void onMenuClosed(FloatingActionMenu floatingActionMenu) {
//                leftCenterMenu1.close(true);
                fabIconStar.setRotation(45);
                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 0);
                ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(fabIconStar, pvhR);
                animator.start();
            }
        });
        //添加客户
        lcIcon1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder;
                builder = new AlertDialog.Builder(new ContextThemeWrapper(SimpleJtCustomerActivity.this, R.style.custom_dialog));
                builder.setTitle("请选择信息录入方式");
                builder.setPositiveButton("手动输入", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(SimpleJtCustomerActivity.this, CustomerAddActivity.class);
                        intent.putExtra("TAG","coor");
                        startActivity(intent);
                    }
                });
                builder.setNegativeButton("仪器扫描", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(SimpleJtCustomerActivity.this, MainActivitycard.class);
                        intent.putExtra("tag","cc");
                        intent.putExtra("TAG","coor");
                        startActivity(intent);
                    }
                });
                builder.show();
            }
        });
        //添加预约
        lcIcon2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (list!=null){
                    final List<Integer> list1= ListViewAdapter.getIDs();
                    if (list1.size()>1){
                        Toast.makeText(SimpleJtCustomerActivity.this, "只能选择一个客户进行预约", Toast.LENGTH_SHORT).show();
                    }else if (list1.size()==0){
                        Toast.makeText(SimpleJtCustomerActivity.this, "请选择一个用户进行预约", Toast.LENGTH_SHORT).show();
                    }else if (list1.size()==1){
                        Intent intent = new Intent(SimpleJtCustomerActivity.this, CustomerAppointmentAcitity.class);
                        intent.putExtra("ID",list1.get(0));
                        intent.putExtra("TAG","coor");
                        startActivity(intent);
                    }
                }
            }
        });
        //全部客户
        lcIcon3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        SC sc = new SC();
                        final JSONObject object = sc.storage(sp);
                        customer_tag = "";
                        try {
                            object.put("custom_button_flag",customer_tag);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        String json = object.toString();
                        String result = NetWorkUtils.getCount(baseClass.find_ALL_CUSTOMER_URL+1,json);
                        list = CoorCustomerJson.jsonVisitMessage(result);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (list!=null){
                                    listView.setVisibility(View.VISIBLE);
                                    adapter = new ListViewAdapter(SimpleJtCustomerActivity.this,list);
                                    listView.setAdapter(adapter);
                                    adapter.notifyDataSetChanged();
                                }else {
                                    listView.setVisibility(View.GONE);
                                    Toast.makeText(SimpleJtCustomerActivity.this, "没有客户信息", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                    }
                }).start();
            }
        });
        //我的客户
        lcIcon4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        SC sc = new SC();
                        final JSONObject object = sc.storage(sp);
                        customer_tag = "my_customs";
                        try {
                            object.put("custom_button_flag",customer_tag);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        String json = object.toString();
                        String result = NetWorkUtils.getCount(baseClass.find_ALL_CUSTOMER_URL+1,json);
                        list = CoorCustomerJson.jsonVisitMessage(result);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (list!=null){
                                    listView.setVisibility(View.VISIBLE);
                                    adapter = new ListViewAdapter(SimpleJtCustomerActivity.this,list);
                                    listView.setAdapter(adapter);
                                    adapter.notifyDataSetChanged();
                                }else {
                                    listView.setVisibility(View.GONE);
                                    Toast.makeText(SimpleJtCustomerActivity.this, "没有客户信息", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                    }
                }).start();
            }
        });
        //回收站
        lcIcon5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        SC sc = new SC();
                        final JSONObject object = sc.storage(sp);
                        customer_tag = "recyle_customs";
                        try {
                            object.put("custom_button_flag",customer_tag);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        String json = object.toString();
                        String result = NetWorkUtils.getCount(baseClass.find_ALL_CUSTOMER_URL+1,json);
                        list = CoorCustomerJson.jsonVisitMessage(result);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (list!=null){
                                    listView.setVisibility(View.VISIBLE);
                                    adapter = new ListViewAdapter(SimpleJtCustomerActivity.this,list);
                                    listView.setAdapter(adapter);
                                    adapter.notifyDataSetChanged();
                                }else {
                                    listView.setVisibility(View.GONE);
                                    Toast.makeText(SimpleJtCustomerActivity.this, "没有客户信息", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                    }
                }).start();
            }
        });

        new Thread(new Runnable() {
            @Override
            public void run() {
                SC sc = new SC();
                final JSONObject object = sc.storage(sp);
                try {
                    object.put("custom_button_flag",customer_tag);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                String json = object.toString();
                String result = NetWorkUtils.getCount(baseClass.find_ALL_CUSTOMER_URL+1,json);
                list = CoorCustomerJson.jsonVisitMessage(result);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(list!=null){
                            adapter = new ListViewAdapter(SimpleJtCustomerActivity.this,list);
                            listView.setAdapter(adapter);
                            a++;
                            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                @Override
                                public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
//                                    GetCustumer.customers = list.get(position-1);
//                                    Intent intent = new Intent(CoorCustomerActivity.this,CustomerDetailedMessageActivity.class);
//                                    startActivity(intent);
                                    new Thread(new Runnable() {
                                        @Override
                                        public void run() {
                                            JSONObject object1 = new JSONObject();
                                            try {
                                                object1.put("KAA01",list.get(position-1).getClient_id());
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }
                                            GetCustumer.create();
                                            GetContact.create();
                                            String json = object1.toString();
                                            String reult = NetWorkUtils.getCount(baseClass.find_customer_msg, json);
                                            GetCustumer.customers = customerJson.jsonCustomerDetailedMessage1(reult,null);
                                            GetContact.contact = contactJson.detailedContactMessageJson1(reult,null);
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    if (GetCustumer.customers!=null&& GetContact.contact!=null){
                                                        Intent intent = new Intent(SimpleJtCustomerActivity.this,CustomerDetailedMessageActivity.class);
                                                        startActivity(intent);
                                                    }

                                                }
                                            });
                                        }
                                    }).start();
                                }
                            });
                        }else {
                            listView.setVisibility(View.GONE);
                            Toast.makeText(SimpleJtCustomerActivity.this, "无客户记录", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        }).start();
        img_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(SimpleJtCustomerActivity.this,CoordingCustomerSearchActivity.class);
                startActivity(intent);
            }
        });
        img_more1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showPopupWindow();
            }
        });
        img_shouye.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SimpleJtCustomerActivity.this, HomeActivity.class);
                startActivity(intent);
            }
        });

    }
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            FloatingActionMenu v = leftCenterMenu;
            if (isShouldHideKeyboard(v, ev)) {
//                Toast.makeText(this, aBoolean+"", Toast.LENGTH_SHORT).show();
                if (leftCenterMenu.isOpen()){
                    leftCenterMenu.close(true);
                }
            }
        }
        return super.dispatchTouchEvent(ev);
    }

    /**
     * 根据控件所在坐标和用户点击的坐标相对比，来判断是否隐藏，因为当用户点击控件时则不能隐藏
     *
     * @param v
     * @param event
     * @return
     */
    private boolean isShouldHideKeyboard(FloatingActionMenu v, MotionEvent event) {
        if (v != null ) {
            int[] l = {100, 100};
            int left = l[0],
                    top = l[1],
                    bottom = top ,
                    right = left ;
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 点击控件的事件，忽略它。
                return false;
            } else {
                return true;
            }
        }
        // 如果焦点不是控件则忽略，这个发生在视图刚绘制完，第一个焦点不在EditText上，和用户用轨迹球选择其他的焦点
        return false;
    }

    @Override
    public void onLoad() {
        loadData(AutoListView.LOAD);
    }

    @Override
    public void onRefresh() {
        loadData(AutoListView.REFRESH);
    }

    public void OnClick(View view) {
        switch (view.getId()){
            case R.id.health_education_img_back:
                finish();
                break;
        }
    }
    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.add_coord_record:
                Intent intent4 = new Intent(SimpleJtCustomerActivity.this,SimpleintmentActivity.class);
//                startActivity(intent4);
                break;
            case R.id.appointment_record:
                Intent intent=new Intent(SimpleJtCustomerActivity.this,CoordingCommunicateActivity.class);
//                startActivity(intent);
                break;
            case R.id.coord_visit:
                Intent intent2 = new Intent(SimpleJtCustomerActivity.this,CoordinationVisitActivitu.class);
//                startActivity(intent2);
                break;
            case R.id.gift_record:
                Intent intent1 = new Intent(SimpleJtCustomerActivity.this,CoordinationGiftActivity.class);
//                startActivity(intent1);
                break;
            case R.id.operation_log:
                Intent intent5 = new Intent(SimpleJtCustomerActivity.this,OperationLogActivity.class);
//                startActivity(intent5);
                break;
        }

    }

    class LoadTask extends AsyncTask<Void,Integer,Integer> {
        Message msg = handler.obtainMessage();
        @Override
        protected Integer doInBackground(Void... voids) {
            int what = 1;
            msg.what = what;
            page=page+1;
            SC sc = new SC();
            JSONObject object = sc.storage(sp);
            try {
                object.put("custom_button_flag",customer_tag);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            String json = object.toString();
            String result = NetWorkUtils.getCount(baseClass.find_ALL_CUSTOMER_URL+page,json);
            alist = CoorCustomerJson.jsonVisitMessage(result);
            return null;
        }
        @Override
        protected void onPostExecute(Integer integer) {
            if (alist!=null){
                msg.obj = alist;
                handler.sendMessage(msg);
            }else {
                msg.obj = alist;
                handler.sendMessage(msg);
                Toast.makeText(SimpleJtCustomerActivity.this, "无更多数据", Toast.LENGTH_SHORT).show();
            }
            super.onPostExecute(integer);
        }
    }
    class UpdateTextTask extends AsyncTask<Void,Integer,Integer> {
        Message msg = handler.obtainMessage();
        @Override
        protected Integer doInBackground(Void... voids) {
            int what = 0;
            msg.what = what;
            page =1;
            SC sc = new SC();
            JSONObject object = sc.storage(sp);
            try {
                object.put("custom_button_flag",customer_tag);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            String json = object.toString();
            String result = NetWorkUtils.getCount(baseClass.find_ALL_CUSTOMER_URL+1,json);
            alist = CoorCustomerJson.jsonVisitMessage(result);
            return null;
        }

        @Override
        protected void onPostExecute(Integer integer) {
            if (alist!=null){
                listView.setVisibility(View.VISIBLE);
                msg.obj = alist;
                handler.sendMessage(msg);
            }else {
                listView.setVisibility(View.GONE);
                Toast.makeText(SimpleJtCustomerActivity.this, "无数据", Toast.LENGTH_SHORT).show();
            }
            super.onPostExecute(integer);
        }
    }
    private void loadData(int refresh) {
        if (refresh== AutoListView.REFRESH){
            UpdateTextTask updateTextTask = new UpdateTextTask();
            updateTextTask.execute();
        }else if(refresh== AutoListView.LOAD){
            LoadTask loadTask = new LoadTask();
            loadTask.execute();
        }

    }

    @Override
    protected void onRestart() {
        super.onRestart();
        if (GetCustomerData.customers!=null){
            list.clear();
            list.addAll(GetCustomerData.customers);
            adapter.notifyDataSetChanged();
            GetCustomerData.customers=null;
        }else {
            onRefresh();
        }
    }
    private void showPopupWindow() {
        View contentView = LayoutInflater.from(SimpleJtCustomerActivity.this).inflate(
                R.layout.popowindow_customer, null);

        mPopWindow = new PopupWindow(contentView);
        mPopWindow.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        mPopWindow.setHeight( LinearLayout.LayoutParams.WRAP_CONTENT);

        contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int popupWidth = contentView.getMeasuredWidth();    //  获取测量后的宽度
        int popupHeight = contentView.getMeasuredHeight();  //获取测量后的高度
        int[] location = new int[2];
        TextView tv2 = (TextView)contentView.findViewById(R.id.add_coord_record);
        TextView tv3 = (TextView)contentView.findViewById(R.id.appointment_record);
        TextView tv4 = (TextView)contentView.findViewById(R.id.coord_visit);
        TextView tv5 = (TextView)contentView.findViewById(R.id.gift_record);
        TextView tv6 = (TextView)contentView.findViewById(R.id.operation_log);
        tv2.setOnClickListener(this);
        tv3.setOnClickListener(this);
        tv4.setOnClickListener(this);
        tv5.setOnClickListener(this);
        tv6.setOnClickListener(this);
        img_more1.getLocationOnScreen(location);
        mPopWindow.setAnimationStyle(R.style.contextMenuAnim);
        mPopWindow.setBackgroundDrawable(getResources().getDrawable(
                R.drawable.pop_bg));
        mPopWindow.setTouchable(true);
        mPopWindow.setOutsideTouchable(true);   //设置外部点击关闭ppw窗口
        mPopWindow.setFocusable(true);
        mPopWindow.update();

        mPopWindow.showAtLocation(img_more1, Gravity.NO_GRAVITY, (location[0] + img_more1.getWidth() / 2) - popupWidth / 2, location[1] - img_more1.getHeight()/2-popupHeight);

    }
    public void  addXuanFu1(){
        /**
         * 一个FloatingActionButton有一个FloatingActionMenu，FloatingActionMenu添加动画弹出的子菜单。
         * FloatingActionButton的按钮点击事件将触发、弹出FloatingActionMenu中包含的子菜单。
         * FloatingActionMenu使用attachTo方法附着在一个FloatingActionButton上。
         * FloatingActionMenu在attachTo到一个FloatingActionButton后，两者之间发生关联。
         * FloatingActionMenu在添加子菜单时候，首先需要一个SubActionButton.Builder，该SubActionButton.
         * Builder通过setContentView(ImageView
         * image).build()把一个ImageView创建生产一个SubActionButton ,
         * 然后通过FloatingActionMenu.Builder的add方法把前面生成的SubActionButton添加进去。
         *
         *
         * 按钮的旋转动画在onMenuOpened和onMenuClosed中做。
         *
         */
        WindowManager wm = (WindowManager) getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE);

        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        //按钮的大小
        int redActionButtonSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_size1);
        //距离下边的长度
        int redActionButtonMargin = 7;
        //距离右边的长度
        int redActionButtonMarginRight = width/2-getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size)/2;
        //按钮中内容的大小
        int redActionButtonContentSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size);
        int redActionButtonContentMargin = getResources()
                .getDimensionPixelSize(R.dimen.red_action_button_content_margin);
        //弹出圆弧的半径
        int redActionMenuRadius = getResources().getDimensionPixelSize(R.dimen.red_action_menu_radius2);
        int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
        int blueSubActionButtonContentMargin = getResources()
                .getDimensionPixelSize(R.dimen.blue_sub_action_button_content_margin);

        fabIconStar = new ImageView(this);
        //按钮中的图片
        fabIconStar.setImageDrawable(getResources().getDrawable(R.drawable.plus5));

        FloatingActionButton.LayoutParams starParams = new FloatingActionButton.LayoutParams(redActionButtonSize,
                redActionButtonSize);
        starParams.setMargins(redActionButtonMargin, redActionButtonMargin, redActionButtonMarginRight,
                redActionButtonMargin);
        fabIconStar.setLayoutParams(starParams);

        FloatingActionButton.LayoutParams fabIconStarParams = new FloatingActionButton.LayoutParams(
                redActionButtonContentSize, redActionButtonContentSize);
        fabIconStarParams.setMargins(redActionButtonContentMargin, redActionButtonContentMargin,
                redActionButtonContentMargin, redActionButtonContentMargin);

        leftCenterButton = new FloatingActionButton.Builder(this)
                .setContentView(fabIconStar, fabIconStarParams)
                .setBackgroundDrawable(R.drawable.button_action_red_selector)// 设置变化时的背景色
                .setPosition(FloatingActionButton.POSITION_BOTTOM_RIGHT)// 靠近右边和下边
                .setLayoutParams(starParams).build();

        // Set up customized SubActionButtons for the right center menu
        SubActionButton.Builder lCSubBuilder = new SubActionButton.Builder(this);
        lCSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));

        FrameLayout.LayoutParams blueContentParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT);
        blueContentParams.setMargins(blueSubActionButtonContentMargin, blueSubActionButtonContentMargin,
                blueSubActionButtonContentMargin, blueSubActionButtonContentMargin);
        lCSubBuilder.setLayoutParams(blueContentParams);
        // Set custom layout params
        FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize,
                blueSubActionButtonSize);
        lCSubBuilder.setLayoutParams(blueParams);

//        ImageView lcIcon1 = new ImageView(this);
//        ImageView lcIcon2 = new ImageView(this);
//        ImageView lcIcon3 = new ImageView(this);
//
//        lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.u116));
//        lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.u117));
//        lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.u118));
        //添加按钮
        lcIcon1 = new ImageView(this);
        lcIcon2 = new ImageView(this);
        lcIcon3 = new ImageView(this);
        lcIcon4 = new ImageView(this);
        lcIcon5 = new ImageView(this);
//         lcIcon4 = new TextView(this);
        lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.u1190));
        lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.u1192));
        lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.all));
        lcIcon4.setImageDrawable(getResources().getDrawable(R.drawable.mine));
        lcIcon5.setImageDrawable(getResources().getDrawable(R.drawable.huishouzhan));
//        lcIcon4.setText("选择部门");

        // Build another menu with custom options
        leftCenterMenu = new FloatingActionMenu.Builder(this)
                .addSubActionView(lCSubBuilder.setContentView(lcIcon1, blueContentParams).build())
                .addSubActionView(lCSubBuilder.setContentView(lcIcon2, blueContentParams).build())
                .addSubActionView(lCSubBuilder.setContentView(lcIcon3, blueContentParams).build())
                .addSubActionView(lCSubBuilder.setContentView(lcIcon4, blueContentParams).build())
                .addSubActionView(lCSubBuilder.setContentView(lcIcon5, blueContentParams).build())
                .setRadius(redActionMenuRadius).setStartAngle(220).setEndAngle(320).attachTo(leftCenterButton).build();



    }
}
